# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-tsdl-image
pkgver=0.6
pkgrel=0
_pkgreal=tsdl-image
pkgdesc="SDL2_Image bindings to go with ocaml-tsdl"
url="https://github.com/sanette/tsdl-image"
arch="all !riscv64 !loongarch64" # ocaml
license="BSD-3-Clause"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-ctypes-dev
	ocaml-tsdl-dev
	sdl2_image-dev
	"
makedepends="
	$depends_dev
	dune
	dune-configurator
	ocaml
	"
checkdepends="
	libffi-dev
	ocaml-bigarray-compat-dev
	ocaml-integers-dev
	"
subpackages="$pkgname-dev"
source="$_pkgreal-$pkgver.tar.gz::https://github.com/sanette/tsdl-image/archive/$pkgver.tar.gz"
builddir="$srcdir/$_pkgreal-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --build-dir=.testenv --verbose
}

package() {
	dune install --destdir="$pkgdir" --docdir=/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
af350af0591197bb3a670c1ed93a00f4bc514a7c2d60da309b574756200b6e34b91bf1886fa36f4eb43529cb0c2f715a2bc2c80b66fae6bdcee87e156ffc4f35  tsdl-image-0.6.tar.gz
"
